﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Brilliants.UI
{
    /// <summary>
    /// NbParkSpaceLamp.xaml 的交互逻辑
    /// </summary>
    public partial class NbParkSpaceLamp : UserControl
    {
        public NbParkSpaceLamp()
        {
            InitializeComponent();
        }



        public Brush OnBrush
        {
            get { return (Brush)GetValue(OnBrushProperty); }
            set { SetValue(OnBrushProperty, value); }
        }

        // Using a DependencyProperty as the backing store for OnBrush.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty OnBrushProperty =
            DependencyProperty.Register("OnBrush", typeof(Brush), typeof(NbParkSpaceLamp), new PropertyMetadata(new SolidColorBrush()));



        public Brush OffBrush
        {
            get { return (Brush)GetValue(OffBrushProperty); }
            set { SetValue(OffBrushProperty, value); }
        }

        // Using a DependencyProperty as the backing store for OffBrush.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty OffBrushProperty =
            DependencyProperty.Register("OffBrush", typeof(Brush), typeof(NbParkSpaceLamp), new PropertyMetadata(new SolidColorBrush()));


        public Brush DisabledBrush
        {
            get { return (Brush)GetValue(DisabledBrushProperty); }
            set { SetValue(DisabledBrushProperty, value); }
        }

        // Using a DependencyProperty as the backing store for DisabledBrush.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty DisabledBrushProperty =
            DependencyProperty.Register("DisabledBrush", typeof(Brush), typeof(NbParkSpaceLamp), new PropertyMetadata(new SolidColorBrush()));


        public ParkSpaceLampState Lamp1State
        {
            get { return (ParkSpaceLampState)GetValue(Lamp1StateProperty); }
            set { SetValue(Lamp1StateProperty, value); SetLampBrush(value, this.Lamp1); }
        }

        // Using a DependencyProperty as the backing store for Lamp1State.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty Lamp1StateProperty =
            DependencyProperty.Register("Lamp1State", typeof(ParkSpaceLampState), typeof(NbParkSpaceLamp), 
                new FrameworkPropertyMetadata(ParkSpaceLampState.Disabled, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, Lamp1StatePropertyChangedCallback));

        public static void Lamp1StatePropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var psl = d as NbParkSpaceLamp;
            psl.Lamp1State = (ParkSpaceLampState)e.NewValue;
        }

        public ParkSpaceLampState Lamp2State
        {
            get { return (ParkSpaceLampState)GetValue(Lamp2StateProperty); }
            set { SetValue(Lamp2StateProperty, value); SetLampBrush(value, this.Lamp2); }
        }

        // Using a DependencyProperty as the backing store for Lamp1State.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty Lamp2StateProperty =
            DependencyProperty.Register("Lamp2State", typeof(ParkSpaceLampState), typeof(NbParkSpaceLamp),
                new FrameworkPropertyMetadata(ParkSpaceLampState.Disabled, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, Lamp2StatePropertyChangedCallback));

        public static void Lamp2StatePropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var psl = d as NbParkSpaceLamp;
            psl.Lamp2State = (ParkSpaceLampState)e.NewValue;
        }

        public ParkSpaceLampState Lamp3State
        {
            get { return (ParkSpaceLampState)GetValue(Lamp3StateProperty); }
            set { SetValue(Lamp3StateProperty, value); SetLampBrush(value, this.Lamp3); }
        }

        // Using a DependencyProperty as the backing store for Lamp1State.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty Lamp3StateProperty =
            DependencyProperty.Register("Lamp3State", typeof(ParkSpaceLampState), typeof(NbParkSpaceLamp),
                new FrameworkPropertyMetadata(ParkSpaceLampState.Disabled, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, Lamp3StatePropertyChangedCallback));

        public static void Lamp3StatePropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var psl = d as NbParkSpaceLamp;
            psl.Lamp3State = (ParkSpaceLampState)e.NewValue;
        }

        public string Lamp1Text
        {
            get { return (string)GetValue(Lamp1TextProperty); }
            set { SetValue(Lamp1TextProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Lamp1Text.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty Lamp1TextProperty =
            DependencyProperty.Register("Lamp1Text", typeof(string), typeof(NbParkSpaceLamp), new PropertyMetadata(string.Empty));

        public string Lamp2Text
        {
            get { return (string)GetValue(Lamp2TextProperty); }
            set { SetValue(Lamp2TextProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Lamp1Text.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty Lamp2TextProperty =
            DependencyProperty.Register("Lamp2Text", typeof(string), typeof(NbParkSpaceLamp), new PropertyMetadata(string.Empty));


        public string Lamp3Text
        {
            get { return (string)GetValue(Lamp3TextProperty); }
            set { SetValue(Lamp3TextProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Lamp1Text.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty Lamp3TextProperty =
            DependencyProperty.Register("Lamp3Text", typeof(string), typeof(NbParkSpaceLamp), new PropertyMetadata(string.Empty));



        public string Lamp1Code
        {
            get { return (string)GetValue(Lamp1CodeProperty); }
            set { SetValue(Lamp1CodeProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Lamp1Code.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty Lamp1CodeProperty =
            DependencyProperty.Register("Lamp1Code", typeof(string), typeof(NbParkSpaceLamp), new PropertyMetadata(string.Empty));

        public string Lamp2Code
        {
            get { return (string)GetValue(Lamp2CodeProperty); }
            set { SetValue(Lamp2CodeProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Lamp2Code.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty Lamp2CodeProperty =
            DependencyProperty.Register("Lamp2Code", typeof(string), typeof(NbParkSpaceLamp), new PropertyMetadata(string.Empty));

        public string Lamp3Code
        {
            get { return (string)GetValue(Lamp3CodeProperty); }
            set { SetValue(Lamp3CodeProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Lamp3Code.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty Lamp3CodeProperty =
            DependencyProperty.Register("Lamp3Code", typeof(string), typeof(NbParkSpaceLamp), new PropertyMetadata(string.Empty));



        private void SetLampBrush(ParkSpaceLampState state, Border lamp)
        {
            switch (state)
            {
                case ParkSpaceLampState.On:
                    lamp.Background = OnBrush;
                    break;
                case ParkSpaceLampState.Off:
                    lamp.Background = OffBrush;
                    break;
                default:
                    lamp.Background = DisabledBrush;
                    break;
            }
        }
    }

    /// <summary>
    /// 车位灯状态
    /// </summary>
    public enum ParkSpaceLampState
    {
        /// <summary>
        /// 禁用
        /// </summary>
        Disabled = 0,
        /// <summary>
        /// 占用
        /// </summary>
        On = 1,
        /// <summary>
        /// 空闲
        /// </summary>
        Off = 2
    }
}
